using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace KbsUmlEditor
{
    class UMLDiagram
    {
        double m_Factor = 1;
        int m_Grid = 1;

        public int Grid
        {
            get { return m_Grid; }
            set { m_Grid = value; }
        }
        string m_Naam;

        public string Naam
        {
            get { return m_Naam; }
            set { m_Naam = value; }
        }
        public double Factor
        {
            get { return m_Factor; }
            set { m_Factor = value; }
        }

        List<UMLObject> m_UMLObjectsList = new List<UMLObject>();

        internal List<UMLObject> UMLObjectsList
        {
            get { return m_UMLObjectsList; }
            set { m_UMLObjectsList = value; }
        }

        Bitmap m_UMLBitmap = new Bitmap(800,600);

        public Bitmap UMLBitmap
        {
            get { return m_UMLBitmap; }
            set { m_UMLBitmap = value; }
        }

        public UMLDiagram(string naam)
        {
            m_Naam = naam;
        }

        public void VoegToeUMLObject(UMLObject umlObject)
        {
            UMLObjectsList.Add(umlObject);
        }
        public void PrintXML()
        {
        }
        public void PrintDiagram()
        {
        }
        public void SetFactor(double factor)
        {
            m_Factor = factor;
            //repaint dmv invalidate
        }

        public  void Teken(Graphics g)
        {
            foreach(UMLObject umlobject in UMLObjectsList)
            {
                umlobject.Teken(g, m_Factor, m_Grid);
            }
        }
       
        public void exportDrawing(Panel p, String extensie)
        {
            Bitmap bmp = new Bitmap(p.Width, p.Height);
            p.DrawToBitmap(bmp, new Rectangle(0, 0, p.Width, p.Height));
            switch (extensie)
            {
                case "Jpeg":
                    bmp.Save("c:\\UMLdrawing.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                case "Gif":
                    bmp.Save("c:\\UMLdrawing.gif", System.Drawing.Imaging.ImageFormat.Gif);
                    break;
            }
        }

        
        System.Drawing.Image printImage;

        
        public void printDrawing(Panel p)
        {
            Bitmap B = new Bitmap(p.Width, p.Height);
            p.DrawToBitmap(B, new Rectangle(0, 0, p.Width, p.Height));
            printImage = B;
            PrintDialog pr = new PrintDialog();
            pr.Document = new System.Drawing.Printing.PrintDocument();
            pr.Document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument2_PrintPage);
            pr.ShowDialog();
            pr.Document.Print();
        }

        
        private void printDocument2_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(printImage, 0, 0);
        }

    }
}
